{include file="public/header" /}


<div class="page">
    <form id="exampaper_form" method="post" enctype="multipart/form-data">
        <table class="ds-default-table">
            <tbody>
                <tr class="noborder"> 
                    <td class="required w120">{$Think.lang.exampaper_name}</td>
                    <td class="vatop rowform"><input type="text" name="exampaper_name" id="exampaper_name" value="{$exampaper.exampaper_name|default=''}" class="w200"/></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder"> 
                    <td class="required w120">{$Think.lang.exampaper_time}</td>
                    <td class="vatop rowform"><input type="text" name="exampaper_time" id="exampaper_time" value="{$exampaper.exampaper_time|default=''}" class="w200"/></td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder"> 
                    <td class="required w120">{$Think.lang.exampaper_type}</td>
                    <td class="vatop rowform">
                        <select name="exampaper_type">
                            <option value="0" {if $exampaper.exampaper_type == 0 }selected{/if}>{$Think.lang.exampaper_type_0}</option>
                            <option value="1" {if $exampaper.exampaper_type == 1 }selected{/if}>{$Think.lang.exampaper_type_1}</option>
                        </select>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                <tr class="noborder"> 
                    <td class="required w120">{$Think.lang.exampaper_goods}</td>
                    <td class="vatop rowform">
                        <input type="hidden" name="goods_id" id="goods_id" value="{$exampaper.goods_id|default=''}"/>
                        <input type="text" id="goods_name" value="{$exampaper.goods_name|default=''}" onkeyup="searchGoods(this)" class="w200"/>
                        <div id="goods_list" class="goods-list"></div>
                    </td>
                    <td class="vatop tips"></td>
                </tr>
                        
                
            </tbody>
            <tfoot>
                <tr class="tfoot">
                    <td colspan="15"><input class="btn" type="submit" value="{$Think.lang.ds_submit}"/></td>
                </tr>	
            </tfoot>
        </table>
    </form>
</div>
<style>
    .goods-list{padding:10px;position:absolute;top:264px;width:250px;border:1px solid #eee;background:#fff;display: none}
    .goods-item{padding:10px}
    .empty-data{text-align:center;padding:10px}
</style>
<script type="text/javascript">
    $(function () {
        $('#exampaper_form').validate({
            errorPlacement: function (error, element) {
                error.appendTo(element.parent().parent().find('td:last'));
            },
            rules: {
                exampaper_question: {
                    required: true
                }
            },
            messages: {
                exampaper_question: {
                    required: '{$Think.lang.exampaper_title_error}'
                }
            }
        });
    });
    function setAnswerHtml(t, o)
    {
        $("." + o).hide();
        $("#" + o + "_" + t).show();
        if (parseInt(t) == 0 || parseInt(t) == 5)
        {
            $("#selectnumber").hide();
            $("#selecttext").hide();
        } else
        {
            $("#selectnumber").show();
            $("#selecttext").show();
        }
    }
    function searchGoods(item){
        $.getJSON('{:url("Exampaper/search_goods")}',{keyword:$(item).val()},function(res){
            $('.goods-list').show()
            var data=res.result
            var html=''
            for(var i in data){
                html+='<div class="goods-item" onclick="selectGoods('+data[i].goods_id+',\''+data[i].goods_name+'\')">'+data[i].goods_name+'</div>'
            }
            if(!html){
                html='<div class="empty-data">没有找到相关记录</div>'
            }
            $('#goods_list').html(html)
        })
    }
    function selectGoods(goods_id,goods_name){
        $('.goods-list').hide()
        $('#goods_id').val(goods_id)
        $('#goods_name').val(goods_name)
    }
</script>